package com.aperos.webservices;

import java.util.ArrayList;
import java.util.List;


public class AperosPasChersService {
	private List<Bar> barList = new ArrayList<Bar>();
	private int maxId = 3;
	
	public List<Bar> getAllBars() {
		
    	if (barList.size() == 0) {
    	
	    	Bar cnom = new Bar(0, 48875159, 2308459, "CNOM", "170 bd haussman", 2);
	    	barList.add(cnom);
	        
	        Bar cnom180 = new Bar(1, 48874995, 2307123, "CNOM180", "180 bd haussman", 3);
	        barList.add(cnom180);
	        
	        Bar florence = new Bar(2, 48874959, 2308436, "Le florence", "161 bd haussman", 4.5);
	        barList.add(florence);
    	}
       
    	return barList;
    }
	
	public String addBar(Integer latitudeE6, Integer longitudeE6, String nom, String address, Double priceBeer) {
		try {
			Bar bar = new Bar(maxId, latitudeE6, longitudeE6, nom, address, priceBeer);
			maxId++;
	        barList.add(bar);
		} catch (Exception e) {
			e.printStackTrace();
			return "failed";
		}
        
		return "OK ";
	}
	
	public Bar getBar(){
		Bar cnom = new Bar(0, 48875159, 2308459, "CNOM", "170 bd haussman", 2);
    	barList.add(cnom);
    	return cnom;
	}

    

	public String editBar(Integer id, String name, String address, Double priceBeer) {
		try {
			if (id != null) {
				barList.get(id).setName(name);
				barList.get(id).setAddress(address);
				barList.get(id).setPriceBeer(priceBeer);
			} else {
				return "failed";
			}
			return "OK";
		} catch (Exception e) {
			e.printStackTrace();
			return "failed";
		}
		
	}
}
